View Javadoc
1 package net.sourceforge.selfesteem.applet; 2 3 import javax.swing.*; 4 import javax.swing.tree.DefaultTreeCellRenderer; 5 import java.awt.*; 6 7 public class MyCellRenderer extends DefaultTreeCellRenderer { 8 private static final Font[] FONTS = new Font[]{ 9 new Font("Arial", Font.BOLD, 16), // root 10 new Font("Arial", Font.BOLD, 14), // iteration 11 new Font("Arial", Font.PLAIN, 14), // story 12 new Font("Arial", Font.PLAIN, 12), // passing/failing 13 new Font("Arial", Font.PLAIN, 12) // test 14 }; 15 16 private static final Icon[] ICONS = new Icon[]{ 17 null, // root 18 newIcon("storyCard.gif"), // iteration 19 newIcon("storyCard.gif"), // story 20 newIcon("passingTests.gif"), // passing/failing 21 newIcon("test.gif") // test 22 }; 23 24 private static final Icon FAILING_TESTS = newIcon("failingTests.gif"); 25 26 private static Icon newIcon(String name) { 27 return new ImageIcon(MyCellRenderer.class.getResource("/images/" + name)); 28 } 29 30 public Component getTreeCellRendererComponent(JTree tree, Object value, 31 boolean sel, 32 boolean expanded, 33 boolean leaf, int row, 34 boolean hasFocus) { 35 super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); 36 MyTreeNode node = (MyTreeNode) value; 37 setIcon(ICONS[node.getLevel()]); 38 setFont(FONTS[node.getLevel()]); 39 // special case 40 if (node.getLevel() == 3 && node.getUserObject().equals("Failing Tests")) { 41 setIcon(FAILING_TESTS); 42 } 43 return this; 44 } 45 }

This page was automatically generated by Maven